package com.example.gybicycle.common.entity;

import com.github.pagehelper.Page;
import lombok.Getter;
import lombok.Setter;

import java.util.List;

@Getter
@Setter
public class NormalPage<T> {

//    @Schema(description = "当前页数")
    private int page;

//    @Schema(description = "每页条数")
    private int size;

//    @Schema(description = "总页数")
    private int totalPage;

//    @Schema(description = "总条数")
    private long totalSize;

//    @Schema(description = "返回数据")
    private List<T> list;

    private NormalPage(Page<T> page){
        super();
        this.page = page.getPageNum();
        this.size = page.getPageSize();
        this.totalPage = page.getPages();
        this.totalSize = page.getTotal();
        this.list = page.getResult();
    }
    private NormalPage(List<T> page){
        super();
        this.page = 1;
        int sizes=0;
        if(page!=null)
            sizes=page.size();
        this.size = sizes;
        this.totalPage = 1;
        this.totalSize = sizes;
        this.list = page;
    }

    public static <T> NormalPage<T> createPage(Page<T> page){
        return new NormalPage<>(page);
    }
    public static <T> NormalPage<T> createPage(List<T> page){
        return new NormalPage<>(page);
    }
}